package com.framework.component.resolver.register;

import com.framework.component.resolver.ValueResolver;
import com.framework.component.resolver.exception.ResolverException;
import org.springframework.stereotype.Component;

@Component
public class ResolverRegister {

    private final ResolverRepository repository;

    public ResolverRegister(ResolverRepository repository) {
        this.repository = repository;
    }

    public void register(ValueResolver resolver) {
        ValueResolver putValue = repository.getResolverRepos().put(resolver.getClass(), resolver);
        if (putValue != null) {
            throw new ResolverException("Duplicate resolver definition:" + resolver.getClass());
        }
    }
}
